d89a7d
@@ -17,9 +17,8 @@
  */
 package org.apache.hadoop.hive.ql.exec.tez;
 
-import java.io.IOException;
+import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.concurrent.Callable;
 
 import org.apache.commons.logging.Log;
@@ -41,11 +40,14 @@
 import org.apache.hadoop.util.StringUtils;
 import org.apache.tez.mapreduce.input.MRInputLegacy;
 import org.apache.tez.mapreduce.processor.MRTaskReporter;
+import org.apache.tez.runtime.api.Input;
 import org.apache.tez.runtime.api.LogicalInput;
 import org.apache.tez.runtime.api.LogicalOutput;
 import org.apache.tez.runtime.api.ProcessorContext;
 import org.apache.tez.runtime.library.api.KeyValueReader;
 
+import com.google.common.collect.Lists;
+
 /**
  * Record processor for fast merging of files.
  */
@@ -219,22 +221,36 @@
private boolean processRow(Object key, Object value) {
   }
 
   private MRInputLegacy getMRInput(Map<String, LogicalInput> inputs) throws Exception {
-    // there should be only one MRInput
-    MRInputLegacy theMRInput = null;
-    LOG.info("VDK: the inputs are: " + inputs);
-    for (Entry<String, LogicalInput> inp : inputs.entrySet()) {
-      if (inp.getValue() instanceof MRInputLegacy) {
-        if (theMRInput != null) {
+    LOG.info("The inputs are: " + inputs);
+
+    // start the mr input and wait for ready event. number of MRInput is expected to be 1
+    List<Input> li = Lists.newArrayList();
+    int numMRInputs = 0;
+    for (LogicalInput inp : inputs.values()) {
+      if (inp instanceof MRInputLegacy) {
+        numMRInputs++;
+        if (numMRInputs > 1) {
           throw new IllegalArgumentException("Only one MRInput is expected");
         }
-        // a better logic would be to find the alias
-        theMRInput = (MRInputLegacy) inp.getValue();
+        inp.start();
+        li.add(inp);
       } else {
-        throw new IOException("Expecting only one input of type MRInputLegacy. Found type: "
-            + inp.getClass().getCanonicalName());
+        throw new IllegalArgumentException("Expecting only one input of type MRInputLegacy." +
+            " Found type: " + inp.getClass().getCanonicalName());
       }
     }
-    theMRInput.init();
+
+    // typically alter table .. concatenate is run on only one partition/one table,
+    // so it doesn't matter if we wait for all inputs or any input to be ready.
+    processorContext.waitForAnyInputReady(li);
+
+    final MRInputLegacy theMRInput;
+    if (li.size() == 1) {
+      theMRInput = (MRInputLegacy) li.get(0);
+      theMRInput.init();
+    } else {
+      throw new IllegalArgumentException("MRInputs count is expected to be 1");
+    }
 
     return theMRInput;
   }
